package workTest;

import java.io.*;

public class work05 {
    //字符流
    public static void f1() throws Exception{
        FileReader fileReader = new FileReader("D:\\a.txt");
        FileWriter fileWriter = new FileWriter("E:\\a.txt");
        char[] chars = new char[1024];
        int len = 0;
        while ((len = fileReader.read(chars)) != -1){
            fileWriter.write(chars,0,len);
            fileWriter.flush();
        }
        fileWriter.close();
        fileReader.close();
    }

    //字节流
    public static void f2()throws Exception{
        FileInputStream fis = new FileInputStream("D:\\a.txt");
        FileOutputStream fos = new FileOutputStream("E:\\a.txt");
        byte[] bytes = new byte[1024*5];
        int len = 0;
        while ((len = fis.read(bytes)) != -1){
            fos.write(bytes,0,len);
            fos.flush();
        }
        fos.close();
        fis.close();
    }

    //缓冲字节流
    public static void f3() throws Exception{
        InputStreamReader isr = new InputStreamReader(new FileInputStream("D:\\a.txt"));
        OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream("E:\\a.txt"));
        char[] chars = new char[1024];
        //byte[] bytes = new byte[1024];
        int len = 0;
        while ((len = isr.read(chars)) != -1){
            osw.write(chars,0,len);
            osw.flush();
        }
        osw.close();
        isr.close();
    }

    //缓冲字符流
    public static void f4()throws Exception{
        BufferedReader bf = new BufferedReader(new FileReader("D:\\a.txt"));
        BufferedWriter bw = new BufferedWriter(new FileWriter("E:\\a.txt"));
        String str = null;
        while ((str = bf.readLine()) != null){
            bw.write(str);
            bw.newLine();
            bw.flush();
        }
        bw.close();
        bf.close();
    }
    public static void main(String[] args) throws Exception{
//        f1();
//        f2();
//        f3();
        f4();
    }
}
